/*
 * @Author: Clark
 * @Email: haixuanwoTxh@gmail.com
 * @Date: 2023-01-12 17:54:08
 * @LastEditors: Clark
 * @LastEditTime: 2023-01-13 15:30:59
 * @Description: file content
 */

#include <signal.h>
#include <errno.h>

#define SIGBAD(signo) ((signo) <= 0 || (signo >= NSIG))

int sigaddset(sigset_t *set, int signo)
{
    if (SIGBAD(signo))
    {
        errno = EINVAL;
        return -1;
    }

    *set |= 1 << (signo -1);    // turn bit on
    return 0;
}

int sigdelset(sigset_t *set, int signo)
{
    if (SIGBAD(signo))
    {
        errno = EINVAL;
        return -1;
    }

    *set &= ~(1 << (signo - 1));
    return 0;
}

int sigismember(const sigset_t *set, int signo)
{
    if (SIGBAD(signo))
    {
        errno = EINVAL;
        return -1;
    }
    return (*set & (1 << (signo -1)) != 0);
}
